package cn.edu.fzu.homemaking.common;

import com.google.common.collect.Lists;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author jiebin
 * @Date 2023/4/2
 */
@Data
public class PageVO<T> {

    private long    total;

    private List<T> data;

    public PageVO(long total, List<T> data) {
        this.total = total;
        this.data = data;
    }


    public static PageVO<?> page(Integer pageNumber, Integer pageSize, List<?> list) {
        if (CollectionUtils.isEmpty(list)) {
            return new PageVO<>(0, new ArrayList<>(0));
        }
        if (pageNumber == null || pageSize == null) {
            return new PageVO<>(list.size(), list);
        }
        List<? extends List<?>> partition = Lists.partition(list, pageSize);
        return new PageVO(list.size(), partition.get(pageNumber - 1));
    }
}
